﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SobrietyEngine.Components;
using SobrietyEngine.Common;

namespace ActorTemplateEditor
{
    public partial class ComponentListForm : Form
    {
        public ComponentListForm()
        {
            InitializeComponent();
        }

        private void ComponentList_Load(object sender, EventArgs e)
        {
            //add component names to list view box
            try
            {
                Dictionary<String, List<ParameterDescription>> pdl;
                pdl = ComponentFactory.GetComponentParameterDescriptions();
                foreach (String compName in pdl.Keys)
                {
                    ListViewItem lvi = new ListViewItem(compName);
                    lvi.Tag = pdl[compName];
                    listView1.Items.Add(lvi);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //update our textbox with a lsit of parameters
            textBox1.Text = "";

            if (listView1.SelectedItems.Count == 0)
                return;

            List<ParameterDescription> pl = (List<ParameterDescription>)listView1.SelectedItems[0].Tag;

            String text = "";
            String tab = "     ";
            foreach (ParameterDescription pd in pl)
            {
                /*
                text += "Parameter Name: "  + pd.Name + Environment.NewLine;
                text += tab + "Description: " + pd.Description + Environment.NewLine;
                text += tab + "Type: " + pd.Type.ToString() + Environment.NewLine;
                if(pd.DefaultValue != null)
                    text += tab + "Default: " + pd.DefaultValue.ToString() + Environment.NewLine;
                 * */

                text += pd.Description + Environment.NewLine;
                text += tab + "(" + pd.Type.ToString() + ")" + pd.Name;
                if (pd.DefaultValue != null)
                    text += " = " + pd.DefaultValue.ToString();

                text += Environment.NewLine;
                text += Environment.NewLine;
                //text += "---------------------------" + Environment.NewLine;
            }

            textBox1.Text = text;
        }
    }
}
